<template>
  <div id="app">
    <h2>测试题</h2>
      <SubjectItem v-for="(item,index) in questions" :key="index" :data="item" @submitAnswer="item.answer=$event">
      </SubjectItem>
    <div>
      <FlagItem v-for="(item,index) in questions" :key="index" :data="item.answer" ref="result">{{index+1 }}.{{ item.answer ==null?'未完成':item.answer==true?'回答正确':'回答错误'}}</FlagItem>
    </div>
  </div>
</template>

<script>
import SubjectItem from './components/SubjectItem.vue';
import FlagItem from './components/FlagItem.vue';
export default {
  components: { SubjectItem, FlagItem },
  data() {
    return {
      questions:[],
    };
  },
  methods:{
    generateQuestions() {
      for (let i = 0; i < 5; i++) {
        const num1 = Math.floor(Math.random() * 10) + 1;
        const num2 = Math.floor(Math.random() * 10) + 1;
        this.questions.push({'num1':num1,'num2':num2 ,'answer':null});
      }
    },
  },
  created() {
    this.generateQuestions();
  }
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>